namespace LayuiMvc.DataEntity.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.File",
                c => new
                    {
                        FileId = c.Int(nullable: false, identity: true),
                        RelationGuid = c.Guid(nullable: false),
                        OriginalFileName = c.String(),
                        SaveFileName = c.String(),
                        RelativeSavePath = c.String(),
                        SavePath = c.String(),
                        FileType = c.String(),
                        UploadTime = c.DateTime(nullable: false),
                        FileSize = c.Int(nullable: false),
                        FileTag = c.String(),
                    })
                .PrimaryKey(t => t.FileId);
            
            CreateTable(
                "dbo.IdentityClaim",
                c => new
                    {
                        ClaimId = c.Int(nullable: false, identity: true),
                        ClaimType = c.String(),
                        ClaimValue = c.String(),
                        ClaimDescription = c.String(),
                    })
                .PrimaryKey(t => t.ClaimId);
            
            CreateTable(
                "dbo.PostCollection",
                c => new
                    {
                        CollectionId = c.Int(nullable: false, identity: true),
                        PostId = c.Int(nullable: false),
                        CollectionUserId = c.Int(nullable: false),
                        CollectionTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.CollectionId)
                .ForeignKey("dbo.IdentityUser", t => t.CollectionUserId, cascadeDelete: true)
                .ForeignKey("dbo.Post", t => t.PostId, cascadeDelete: true)
                .Index(t => t.PostId)
                .Index(t => t.CollectionUserId);
            
            CreateTable(
                "dbo.IdentityUser",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        NickName = c.String(),
                        RegisterTime = c.DateTime(nullable: false),
                        Sex = c.Int(nullable: false),
                        IsBanned = c.Boolean(nullable: false),
                        HeadImgUrl = c.String(),
                        UserIdentity = c.Int(nullable: false),
                        IsApprove = c.Boolean(nullable: false),
                        ApproveMsg = c.String(),
                        City = c.String(),
                        Introduce = c.String(),
                        Email = c.String(maxLength: 256),
                        EmailConfirmed = c.Boolean(nullable: false),
                        PasswordHash = c.String(),
                        SecurityStamp = c.String(),
                        PhoneNumber = c.String(),
                        PhoneNumberConfirmed = c.Boolean(nullable: false),
                        TwoFactorEnabled = c.Boolean(nullable: false),
                        LockoutEndDateUtc = c.DateTime(),
                        LockoutEnabled = c.Boolean(nullable: false),
                        AccessFailedCount = c.Int(nullable: false),
                        UserName = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.UserName, unique: true, name: "UserNameIndex");
            
            CreateTable(
                "dbo.IdentityUserClaim",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        ClaimType = c.String(),
                        ClaimValue = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.IdentityUser", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.IdentityUserLogin",
                c => new
                    {
                        LoginProvider = c.String(nullable: false, maxLength: 128),
                        ProviderKey = c.String(nullable: false, maxLength: 128),
                        UserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
                .ForeignKey("dbo.IdentityUser", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.IdentityUserRole",
                c => new
                    {
                        UserId = c.Int(nullable: false),
                        RoleId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("dbo.IdentityUser", t => t.UserId, cascadeDelete: true)
                .ForeignKey("dbo.IdentityRole", t => t.RoleId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.Post",
                c => new
                    {
                        PostId = c.Int(nullable: false, identity: true),
                        RelationGuid = c.Guid(nullable: false),
                        Title = c.String(),
                        PostType = c.Int(nullable: false),
                        Content = c.String(),
                        HtmlContent = c.String(),
                        PublishTime = c.DateTime(nullable: false),
                        ViewCount = c.Int(nullable: false),
                        PublishUserId = c.Int(nullable: false),
                        IsDelete = c.Boolean(nullable: false),
                        IsTop = c.Boolean(nullable: false),
                        IsCream = c.Boolean(nullable: false),
                        IsEnd = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.PostId)
                .ForeignKey("dbo.IdentityUser", t => t.PublishUserId)
                .Index(t => t.PublishUserId);
            
            CreateTable(
                "dbo.PostReply",
                c => new
                    {
                        ReplyId = c.Int(nullable: false, identity: true),
                        ReplyContent = c.String(),
                        ReplyContentHtml = c.String(),
                        PostId = c.Int(nullable: false),
                        RelationGuid = c.Guid(nullable: false),
                        ReplyTime = c.DateTime(nullable: false),
                        IsAccept = c.Boolean(nullable: false),
                        ReplyUserId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ReplyId)
                .ForeignKey("dbo.Post", t => t.PostId, cascadeDelete: true)
                .ForeignKey("dbo.IdentityUser", t => t.ReplyUserId, cascadeDelete: true)
                .Index(t => t.PostId)
                .Index(t => t.ReplyUserId);
            
            CreateTable(
                "dbo.IdentityRole",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Description = c.String(),
                        CreateTime = c.DateTime(nullable: false),
                        UpdateTime = c.DateTime(nullable: false),
                        Name = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Name, unique: true, name: "RoleNameIndex");
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.IdentityUserRole", "RoleId", "dbo.IdentityRole");
            DropForeignKey("dbo.PostCollection", "PostId", "dbo.Post");
            DropForeignKey("dbo.PostReply", "ReplyUserId", "dbo.IdentityUser");
            DropForeignKey("dbo.PostReply", "PostId", "dbo.Post");
            DropForeignKey("dbo.Post", "PublishUserId", "dbo.IdentityUser");
            DropForeignKey("dbo.PostCollection", "CollectionUserId", "dbo.IdentityUser");
            DropForeignKey("dbo.IdentityUserRole", "UserId", "dbo.IdentityUser");
            DropForeignKey("dbo.IdentityUserLogin", "UserId", "dbo.IdentityUser");
            DropForeignKey("dbo.IdentityUserClaim", "UserId", "dbo.IdentityUser");
            DropIndex("dbo.IdentityRole", "RoleNameIndex");
            DropIndex("dbo.PostReply", new[] { "ReplyUserId" });
            DropIndex("dbo.PostReply", new[] { "PostId" });
            DropIndex("dbo.Post", new[] { "PublishUserId" });
            DropIndex("dbo.IdentityUserRole", new[] { "RoleId" });
            DropIndex("dbo.IdentityUserRole", new[] { "UserId" });
            DropIndex("dbo.IdentityUserLogin", new[] { "UserId" });
            DropIndex("dbo.IdentityUserClaim", new[] { "UserId" });
            DropIndex("dbo.IdentityUser", "UserNameIndex");
            DropIndex("dbo.PostCollection", new[] { "CollectionUserId" });
            DropIndex("dbo.PostCollection", new[] { "PostId" });
            DropTable("dbo.IdentityRole");
            DropTable("dbo.PostReply");
            DropTable("dbo.Post");
            DropTable("dbo.IdentityUserRole");
            DropTable("dbo.IdentityUserLogin");
            DropTable("dbo.IdentityUserClaim");
            DropTable("dbo.IdentityUser");
            DropTable("dbo.PostCollection");
            DropTable("dbo.IdentityClaim");
            DropTable("dbo.File");
        }
    }
}
